<?php
set_include_path ( get_include_path () . PATH_SEPARATOR . '../' );
include_once 'Include.php';

$user = req('user');
$password = req('password');
if($user != "" && $password != ""){
	$userTable = new UserTable();
	$d = $userTable->login($user,$password);
	$count = count($d);
	if($count > 0){
		$_SESSION['user']['id'] = $d[0]['id'];
		$_SESSION['user']['name'] = $d[0]['username'];
		header( 'Location: index.php' ) ;
	}else{
		echo "username and password is error.";	
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
<link rel="stylesheet" type="text/css" href="../css/G.css" />
<script type="text/javascript" src="../js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="<?=YUI_PATH?>build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="<?=YUI_PATH?>build/connection/connection-min.js"></script>
<script type="text/javascript">
var  Dom = YAHOO.util.Dom,
     Event = YAHOO.util.Event;
</script>
</head>

<body>
<form action="" method="post" onsubmit="return checkForm()">
<table border="1" width="300px">
	<tr>
		<td>User Name:</td>
		<td><input type="text" id="user" name="user" /></td>
	</tr>
	<tr>
		<td>Password</td>
		<td><input type="password" id="password" name="password" /></td>
	</tr>
	<tr>
		<td align="right"><input type="submit" value=" sign in " /> </td>
		<td> <a href="get_pwd.php">forgot my password</a></td>
	</tr>
</table>
</form>
<script type="text/javascript">
function checkForm(){	
	var user = $("#user").val();
	var password = $("#password").val();
	if(user == "") $("#user").addClass("warn");
	if(password == "") $("#password").addClass("warn");
	
	if(user && password){
		return true;	
	}
	return false;
}
</script>
</body>
</html>

